/**
 *
 * Created by cy on 2017/6/14.
 *
 */
'use strict';

var gulp            = require('gulp'),
    browserSync     = require('browser-sync').create(),             //  
    reload          = browserSync.reload ,
    sass            = require('gulp-sass'),
    plumber         = require('gulp-plumber'),
    sourcemaps      = require('gulp-sourcemaps'),
    autoprefixer    = require('gulp-autoprefixer');

// 监听sass文件+sass编译
gulp.task('scss',function(){
    gulp.src('public/static/index/scss/*.scss')
    .pipe(plumber())
    .pipe(sourcemaps.init())
    .pipe(sass())
    .pipe(autoprefixer())
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('public/static/index/css/'))
    .pipe(reload({stream: true}));   
});

// 监听sass文件+sass编译
gulp.task('mobilescss',function(){
    gulp.src('public/static/mobile/scss/*.scss')
    .pipe(plumber())
    .pipe(sourcemaps.init())
    .pipe(sass())
    .pipe(autoprefixer())
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('public/static/mobile/css/'))
    .pipe(reload({stream: true}));   
});

// serve
gulp.task('serve',['scss','mobilescss'],function(){
    browserSync.init({
        proxy: "elvtuan.mac.com",
        baseDir: "./",
        port: 8011,
        notify:false,
        browser: "google chrome"
    });
    // pc
    gulp.watch('public/static/index/scss/*.scss',['scss']);
    gulp.watch('app/index/**/*.html').on('change',reload);
    // mobile
    gulp.watch('public/static/mobile/scss/*.scss',['mobilescss']);
    gulp.watch('app/mobile/**/*.html').on('change',reload);
})



gulp.task('default',['serve']);